package cn.jhc.servlet;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.jhc.bean.UserBean;
import cn.jhc.dao.ConnectionFactory;
import cn.jhc.dao.NewUserDao;
import cn.jhc.dao.ShowmvDAO;

@WebServlet(name = "add yes", urlPatterns = { "/yes.do" })
public class AddYesServlet extends HttpServlet {
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		req.setCharacterEncoding("UTF-8");
		UserBean user = (UserBean) req.getSession().getAttribute("user");
		if (null == user) {
			String getb = (String) req.getParameter("getb");
			String id = (String) req.getParameter("id");
			req.setAttribute("id", id);
			req.setAttribute("getb", getb);
			RequestDispatcher dispatcher = req
					.getRequestDispatcher("/login.jsp");
			dispatcher.forward(req, resp);
			return;
		}
		String I = (String) req.getParameter("i");
		int i = Integer.parseInt(I);
		String Id = (String) req.getParameter("id");
		int id = Integer.parseInt(Id);
		ShowmvDAO dao = new ShowmvDAO();
		dao.setCon(ConnectionFactory.getConnection());
		dao.UpdateAgreed(i,id);
		int userid = user.getId();
		NewUserDao dao2 = new NewUserDao();
		dao2.setCon(ConnectionFactory.getConnection());
		dao2.updateVote(userid); 
		RequestDispatcher dispatcher = req.getRequestDispatcher("/showonemv.jsp");
		dispatcher.forward(req, resp);
	}
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doGet(req, resp);
	}

}
